<html>
<head><meta charset="utf-8"><title>Sharing name resolution · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Sharing.20name.20resolution.html">Sharing name resolution</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="205147497"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Sharing%20name%20resolution/near/205147497" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Sharing.20name.20resolution.html#205147497">(Jul 27 2020 at 17:50)</a>:</h4>
<p><span class="user-mention" data-user-id="211727">@Jonas Schievink</span> , here's a sketch of name-res API I've been investigating over the weekend: <a href="https://gist.github.com/matklad/145c88131282e8392e64d088ee8a50e4">https://gist.github.com/matklad/145c88131282e8392e64d088ee8a50e4</a></p>



<a name="205147513"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Sharing%20name%20resolution/near/205147513" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Sharing.20name.20resolution.html#205147513">(Jul 27 2020 at 17:50)</a>:</h4>
<p>I think this subset can be shared between rustc &amp; ra in theory</p>



<a name="205147682"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Sharing%20name%20resolution/near/205147682" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Sharing.20name.20resolution.html#205147682">(Jul 27 2020 at 17:52)</a>:</h4>
<p>where subset:</p>
<p>The set of scopes which store <code>Map&lt;Name, PerNs&lt;Def&gt;&gt;</code>, imports (<code>(Vec&lt;Name&gt;, glob or name or alias)</code>) and has operations for:</p>
<ul>
<li>creating a new scope</li>
<li>seeding a new name in given namespaces in scope</li>
<li>adding new import to scope</li>
</ul>
<p>This thing should be enough to run the fixed-point loop (the most interesting part)</p>



<a name="205147797"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Sharing%20name%20resolution/near/205147797" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Sharing.20name.20resolution.html#205147797">(Jul 27 2020 at 17:53)</a>:</h4>
<p>It doesn't know anything about AST (scopes are just bags of names, defs are opaque), hygiene (which is encapsulated into <code>==</code> of names) and which def belongs to which namespaces (the client specifies namespaces explicitely)</p>



<a name="205148129"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Sharing%20name%20resolution/near/205148129" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Sharing.20name.20resolution.html#205148129">(Jul 27 2020 at 17:56)</a>:</h4>
<p>Cool! I guess a good first step would be to make r-a always pass the scope to resolve names in then?</p>



<a name="205149646"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Sharing%20name%20resolution/near/205149646" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Sharing.20name.20resolution.html#205149646">(Jul 27 2020 at 18:10)</a>:</h4>
<p>Not sure, I might be overlooking things.  My plan for this was to create an <a href="http://ires.rs">ires.rs</a> module in hir_def, with the constraint that it <em>doesnt</em> import db directly, and see how much of name resolution can we spill there.</p>



<a name="205149894"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Sharing%20name%20resolution/near/205149894" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Sharing.20name.20resolution.html#205149894">(Jul 27 2020 at 18:12)</a>:</h4>
<p>One open question is how to <em>use</em> this thing after names are resolved ? Should we drain scopes back into ModuleDats, or should we use them as is?</p>



<a name="205150123"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Sharing%20name%20resolution/near/205150123" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Sharing.20name.20resolution.html#205150123">(Jul 27 2020 at 18:14)</a>:</h4>
<p>Should this module extraction succeeded, it would be fun to think about moving this to a crate, with the usual tradeoff:</p>
<ul>
<li>either you make everything generic over a type family (which is bad)</li>
<li>or you pick a set of specific types which is good enough for all consumers (which might be impossible)</li>
</ul>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>